//
//  PotentialAssociateTableViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/10/11.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit

class PotentialAssociateTableViewController: ProjectAssociateViewController {

//    var projName: String?
//
//    var projSerialNum: String?
//
//    var projManager: String?
//
//    var purchaseItemName: String?
//
//    var purchasePredicateNum: String?
//
//    var contractName: String?
//
//    var contractNum: String?
//
//    var contractMoney: String?
    
    var number = ""
    
    var packetnumber = ""
    
    var notifynumber = ""
    
    var money = ""
    
    var date = ""
    
    var projectnum = ""
    
    var projectname = ""
    
    var projectbelong = ""
    
    var projectmanager = ""
    
    var begintime = ""
    
    
    
    override var contents: Array<String?>{
        get{
            return [number,packetnumber,notifynumber,money,date,projectnum,projectname,contractMoney,projectbelong,projectmanager,begintime]
        }
    }
    
    
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        self.tableView.register(UINib.init(nibName: "ApprovalDetailCell", bundle: Bundle.main), forCellReuseIdentifier: "ApprovalDetailCell")
        
        self.tableView.backgroundColor = UIColor.dftBack
        
        self.tableView.tableFooterView = UIView()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - Table view data source
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 2
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        switch section {
        case 1:
            return 5
        default:
            return 5
        }
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        return tableView.dequeueReusableCell(withIdentifier: "ApprovalDetailCell")!
        
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if let content = contents[indexPath.section * 5 + indexPath.row] {
            let size = content.size(with: UIFont.systemFont(ofSize: 18), maxSize: CGSize.init(width: tableView.width - 40, height: 1000000))
            return 60 + size.height
        } else {
            return 50
        }
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 65
    }
    
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
        
        let view = UIView()
        
        view.backgroundColor = UIColor.dftBack
        
        let bottom = UIView()
        
        bottom.backgroundColor = .white
        
        bottom.left = 0
        
        bottom.top = 10
        
        bottom.width = tableView.width
        
        bottom.height = 55
        
        view.addSubview(bottom)
        
        let label = UILabel()
        
        label.frame = CGRect.init(origin: CGPoint.zero, size: CGSize(width: 100, height: 55))
        
        label.textColor = .mainColor
        
        label.left = 0
        
        label.backgroundColor = .white
        
        label.textAlignment = .center
        
        if section == 0 {
            label.text = "关联项目"
        } else {
            label.text = "关联合同"
        }
        
        bottom.addSubview(label)
        
        return view
        
    }
    
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
        if let cel = cell as? ApprovalDetailCell {
            
            if indexPath.section == 0 {
                if indexPath.row == 0 {
                    
                    cel.title = "项目名称:"
                    
                    cel.content = contents[0]
                    
                } else if indexPath.row == 1 {
                    
                    cel.title = "项目编号:"
                    
                    cel.content = contents[1]
                    
                } else if indexPath.row == 2 {
                    
                    cel.title = "项目负责人"
                    
                    cel.content = contents[2]
                    
                } else if indexPath.row == 3 {
                    
                    cel.title = "采购项名称"
                    
                    cel.content = purchaseItemName
                    
                } else if indexPath.row == 4 {
                    
                    cel.title = "采购项预算金额(元)"
                    
                    cel.content = purchasePredicateNum
                    
                }
            } else {
                if indexPath.row == 0 {
                    
                    cel.title = "合同名称:"
                    
                    cel.content = contractName
                    
                } else if indexPath.row == 1 {
                    
                    cel.title = "合同编号:"
                    
                    cel.content = contractNum
                    
                } else if indexPath.row == 2 {
                    
                    cel.title = "合同签订金额:"
                    
                    cel.content = contractMoney
                    
                }
            }
            
        }
        
        
    }
    
    


}
